package cn.doitedu;

import org.roaringbitmap.longlong.Roaring64Bitmap;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;

public class BitmapUtils {

    public static byte[] ser(Roaring64Bitmap bm) throws IOException {

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        DataOutputStream dout = new DataOutputStream(bout);

        bm.serialize(dout);

        byte[] bytes = bout.toByteArray();

        dout.close();
        bout.close();

        return bytes;
    }



    public static Roaring64Bitmap de(byte[] bytes) throws IOException {
        Roaring64Bitmap bitmap = Roaring64Bitmap.bitmapOf();
        bitmap.deserialize(ByteBuffer.wrap(bytes));
        return bitmap;
    }


}
